package asteroids.model.programs.Statement;

import asteroids.model.programs.Program;
import asteroids.model.programs.Expression.Expression;
import asteroids.model.programs.Expression.IBooleanExpression;
import asteroids.model.programs.Expression.IDoubleExpression;
import asteroids.model.programs.Expression.IEntityExpression;
import asteroids.model.programs.Expression.VariableLiteral;

/**
* 
* @version 0.3
* @author  Tandan Sunil, Van Deun Luca
*
*/
public class AssignmentLiteral extends ShortStatement {

	public AssignmentLiteral(int line, int column,String variable, Expression rhs) {
		super(line, column,rhs);
		if(variable == null || rhs ==null)
			throw new IllegalArgumentException();
		this.name = variable;
	}
	
	private String name;
	public String getName() {
		return name;
	}
	
	@Override
	public void execute(Program program) {
		VariableLiteral vl = program.getVariableOf(getName());
		if(vl != null){
			vl.setType((program.getGlobals().get(getName())));
			if(getExpression() instanceof IDoubleExpression){
				vl.setValue(((IDoubleExpression)getExpression()).getValue());
				
			}
			if(getExpression() instanceof IBooleanExpression){
				vl.setBoolean(((IBooleanExpression)getExpression()).getBoolean());

			}
			if(getExpression() instanceof IEntityExpression){
				vl.setEntity(((IEntityExpression)getExpression()).getEntity());

			}
			if(vl.getType() == null){
				vl.setType(getExpression().getType());
			}
//			program.changeGlobalVariable(vl);
		}
	setExecuted(true);
		
			
		
	}
	


}
